/**
 * 
 */
package com.designpattern.design.strategy.improve;

/**
 * @author zhangyang
 *
 */
public class StrategyTest {
public static void main(String[] args) {
	//初始化三种鸭子-都调用飞叫display方法
	BeijingDuck beijingDuck = new BeijingDuck();
	beijingDuck.display();
	beijingDuck.fly();
	beijingDuck.shout();
	System.out.println("========================");
	WildDuck wildDuck = new WildDuck();
	wildDuck.display();
	wildDuck.fly();
	wildDuck.shout();
	System.out.println("========================");
	ToyDuck toyDuck = new ToyDuck();
	toyDuck.display();
	toyDuck.fly();
	toyDuck.shout();
}
}

/**
 * 鸭子策略接口-飞
 * @author zhangyang
 *
 */
interface FlyBehavior{
	public void fly();
}

class GoodsFlyBehavior implements  FlyBehavior{

	@Override
	public void fly() {
		// TODO Auto-generated method stub
		System.out.println("飞的很好");
	}
	
}

class BadFlyBehavior implements FlyBehavior{

	@Override
	public void fly() {
		// TODO Auto-generated method stub
		System.out.println("飞的很差");
	}
	
}

class NoFlyBehavior implements FlyBehavior{

	@Override
	public void fly() {
		// TODO Auto-generated method stub
		System.out.println("不会飞");
	}
	
}

/**
 * 鸭子策略-叫
 * @author zhangyang
 *
 */
interface ShoutBehavior{
	public void shout();
}

class CanShoutBehavior implements  ShoutBehavior{

	@Override
	public void shout() {
		// TODO Auto-generated method stub
		System.out.println("鸭子会叫");
	}
	
}

class NoShoutBehavior implements  ShoutBehavior{

	@Override
	public void shout() {
		// TODO Auto-generated method stub
		System.out.println("鸭子不会叫");
	}
	
}

/**
 * 抽象类-鸭子
 * @author zhangyang
 *
 */
abstract class Duck{
	//策略-飞
	FlyBehavior fly;
	//策略-叫
	ShoutBehavior shout;
	//公有属性-名称
	String name;
	
	//公有方法-都可以游泳
	public void swim() {
		System.out.println("鸭子能游泳");
	}
	//公有方法 -鸭子叫策略
	public void shout() {
		if(shout!=null) {
			shout.shout();
			return;
		}
		System.out.println("系统默认鸭子能叫");
		return ;
	}
	//公有方法-鸭子飞策略
	public void fly() {
		if(fly!=null) {
			fly.fly();
			return;
		}
		System.out.println("系统默认鸭子能飞");
		return ;
	}
	//具体方法
	public abstract void display();
}

class BeijingDuck extends Duck{

	public BeijingDuck() {
		//初始化他的飞行为-不会飞
		fly=new NoFlyBehavior();
		//初始化他的叫行为-不会叫
		shout=new NoShoutBehavior();
	}

	/* (non-Javadoc)
	 * @see com.design.strategy.improve.Duck#display()
	 */
	@Override
	public void display() {
		// TODO Auto-generated method stub
		System.out.println("这是北京烤鸭");
	}
	
}

class WildDuck extends Duck{

	public WildDuck() {
		//初始化他的飞行为-飞的好
		fly=new GoodsFlyBehavior();
		//初始化他的叫行为-会叫
		shout=new CanShoutBehavior();
	}

	@Override
	public void display() {
		// TODO Auto-generated method stub
		System.out.println("这是野鸭");
	}
	
}

class ToyDuck extends Duck{

	//不构造 让他走默认方法
	
	@Override
	public void display() {
		// TODO Auto-generated method stub
		System.out.println("这是玩具鸭");
	}
	
}